Percent-Encoded Strings for Rust
This crate provides two types, [PctStr
] and [PctString
], similar to [str
] and [String
],
representing percent-encoded strings used in URL, URI, IRI, etc.
You can use them to encode, decode and compare percent-encoded strings.
Basic usage
You can parse/decode percent-encoded strings by building a [PctStr
] slice over a [str
] slice.
use PctStr;
let pct_str = new.unwrap;
assert_eq!;
let decoded_string: String = pct_str.decode;
assert_eq!
To create new percent-encoded strings, use the [PctString
] to copy or encode new strings.
use ;
// Copy the given percent-encoded string.
let pct_string = new.unwrap;
// Encode the given regular string.
let pct_string = encode;
assert_eq!;
You can choose which character will be percent-encoded by the encode
function
by implementing the [Encoder
] trait.
use ;
;
let pct_string = encode;
assert_eq!
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.